/**
 * <copyright>
 *
 * Copyright (c) 2011 Zeligsoft (2009) Limited
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors: 
 *   Zeligsoft (2009) Limited - Initial API and implementation
 *
 * </copyright>
 *
 */
package org.omg.deployment.parts.impl;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent;
import org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart;
import org.eclipse.emf.eef.runtime.impl.notify.PropertiesEditionEvent;
import org.eclipse.emf.eef.runtime.impl.parts.CompositePropertiesEditionPart;
import org.eclipse.emf.eef.runtime.ui.parts.PartComposer;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.BindingCompositionSequence;
import org.eclipse.emf.eef.runtime.ui.parts.sequence.CompositionSequence;
import org.eclipse.emf.eef.runtime.ui.utils.EditingUtils;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableContentProvider;
import org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings;
import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.TableColumn;
import org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart;
import org.omg.deployment.parts.DeploymentViewsRepository;
import org.omg.deployment.providers.DeploymentMessages;


/**
 * @author Toby McClean; Zeligsoft (2009) Limited
 * @generated
 */
public class ConnectionEndsPropertiesEditionPartImpl extends CompositePropertiesEditionPart implements ISWTPropertiesEditionPart, ConnectionEndsPropertiesEditionPart {

	protected TableViewer ends;
	protected List<ViewerFilter> endsBusinessFilters = new ArrayList<ViewerFilter>();
	protected List<ViewerFilter> endsFilters = new ArrayList<ViewerFilter>();



	protected TableViewer externalEndPoint;
  protected List<ViewerFilter> externalEndPointBusinessFilters = new ArrayList<ViewerFilter>();
  protected List<ViewerFilter> externalEndPointFilters = new ArrayList<ViewerFilter>();
  protected TableViewer externalReference;
  protected List<ViewerFilter> externalReferenceBusinessFilters = new ArrayList<ViewerFilter>();
  protected List<ViewerFilter> externalReferenceFilters = new ArrayList<ViewerFilter>();



  /**
	 * Default constructor
	 * @param editionComponent the {@link IPropertiesEditionComponent} that manage this part
	 * @generated
	 */
	public ConnectionEndsPropertiesEditionPartImpl(IPropertiesEditionComponent editionComponent) {
    super(editionComponent);
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart#
	 * 			createFigure(org.eclipse.swt.widgets.Composite)
	 * @generated
	 */
	public Composite createFigure(final Composite parent) {
    view = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    view.setLayout(layout);
    createControls(view);
    return view;
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.parts.ISWTPropertiesEditionPart#
	 * 			createControls(org.eclipse.swt.widgets.Composite)
	 * @generated
	 */
	public void createControls(Composite view) { 
    CompositionSequence connectionEndsStep = new BindingCompositionSequence(propertiesEditionComponent);
    connectionEndsStep
      .addStep(DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.class)
      .addStep(DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends);
    
    connectionEndsStep
      .addStep(DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.class)
      .addStep(DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_);
    
    connectionEndsStep
      .addStep(DeploymentViewsRepository.ConnectionEnds.ExternalReference.class)
      .addStep(DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_);
    
    
    composer = new PartComposer(connectionEndsStep) {

      @Override
      public Composite addToPart(Composite parent, Object key) {
        if (key == DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.class) {
          return createInternalEndPointGroup(parent);
        }
        if (key == DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends) {
          return createEndsTableComposition(parent);
        }
        if (key == DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.class) {
          return createExternalEndPointGroup(parent);
        }
        if (key == DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_) {
          return createExternalEndPointTableComposition(parent);
        }
        if (key == DeploymentViewsRepository.ConnectionEnds.ExternalReference.class) {
          return createExternalReferenceGroup(parent);
        }
        if (key == DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_) {
          return createExternalReferenceTableComposition(parent);
        }
        return parent;
      }
    };
    composer.compose(view);
  }

	/**
   * @generated
   */
  protected Composite createInternalEndPointGroup(Composite parent) {
    Group internalEndPointGroup = new Group(parent, SWT.NONE);
    internalEndPointGroup.setText(DeploymentMessages.ConnectionEndsPropertiesEditionPart_InternalEndPointGroupLabel);
    GridData internalEndPointGroupData = new GridData(GridData.FILL_HORIZONTAL);
    internalEndPointGroupData.horizontalSpan = 3;
    internalEndPointGroup.setLayoutData(internalEndPointGroupData);
    GridLayout internalEndPointGroupLayout = new GridLayout();
    internalEndPointGroupLayout.numColumns = 3;
    internalEndPointGroup.setLayout(internalEndPointGroupLayout);
    return internalEndPointGroup;
  }

  /**
	 * @param container
	 * @generated
	 */
	protected Composite createEndsTableComposition(Composite container) {
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridLayout tableContainerLayout = new GridLayout();
    GridData tableContainerData = new GridData(GridData.FILL_BOTH);
    tableContainerData.horizontalSpan = 3;
    tableContainer.setLayoutData(tableContainerData);
    tableContainerLayout.numColumns = 2;
    tableContainer.setLayout(tableContainerLayout);
    org.eclipse.swt.widgets.Table tableEnds = new org.eclipse.swt.widgets.Table(tableContainer, SWT.FULL_SELECTION);
    tableEnds.setHeaderVisible(true);
    tableEnds.setEnabled(false);
    tableEnds.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData gdEnds = new GridData();
    gdEnds.grabExcessHorizontalSpace = true;
    gdEnds.horizontalAlignment = GridData.FILL;
    gdEnds.grabExcessVerticalSpace = true;
    gdEnds.verticalAlignment = GridData.FILL;
    tableEnds.setLayoutData(gdEnds);
    tableEnds.setLinesVisible(true);

        TableColumn name = new TableColumn(tableEnds, SWT.NONE);
        name.setWidth(80);
        name.setText("Label"); //$NON-NLS-1$

    ends = new TableViewer(tableEnds);
    ends.setContentProvider(new ArrayContentProvider());
    ends.setLabelProvider(new ITableLabelProvider() {
            public String getColumnText(Object object, int columnIndex) {
              AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
              if (object instanceof EObject) {
                switch (columnIndex) {
                case 0:
                  return labelProvider.getText(object);
                }
              }
              return ""; //$NON-NLS-1$
            }
      
            public Image getColumnImage(Object element, int columnIndex) {
              return null;
            }
      

      public void addListener(ILabelProviderListener listener) {
      }

      public void dispose() {
      }

      public boolean isLabelProperty(Object element, String property) {
        return false;
      }

      public void removeListener(ILabelProviderListener listener) {
      }

    });
    ends.getTable().addListener(SWT.MouseDoubleClick, new Listener(){

      public void handleEvent(Event event) {
        if (ends.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) ends.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
            ends.refresh();
          }
        }
      }

    });
    GridData endsData = new GridData(GridData.FILL_HORIZONTAL);
    endsData.minimumHeight = 120;
    endsData.heightHint = 120;
    ends.getTable().setLayoutData(endsData);
    for (ViewerFilter filter : this.endsFilters) {
      ends.addFilter(filter);
    }
    EditingUtils.setID(ends.getTable(), DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends);
    EditingUtils.setEEFtype(ends.getTable(), "eef::TableComposition::field"); //$NON-NLS-1$
    createEndsPanel(tableContainer);
    return container;
  }

	/**
	 * @param container
	 * @generated
	 */
	protected Composite createEndsPanel(Composite container) {
    Composite endsPanel = new Composite(container, SWT.NONE);
    GridLayout endsPanelLayout = new GridLayout();
    endsPanelLayout.numColumns = 1;
    endsPanel.setLayout(endsPanelLayout);
    Button addEnds = new Button(endsPanel, SWT.NONE);
    addEnds.setText(DeploymentMessages.PropertiesEditionPart_AddTableViewerLabel);
    addEnds.setEnabled(false);
    addEnds.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData addEndsData = new GridData(GridData.FILL_HORIZONTAL);
    addEnds.setLayoutData(addEndsData);
    addEnds.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, null));
        ends.refresh();
      }
    });
    EditingUtils.setID(addEnds, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends);
    EditingUtils.setEEFtype(addEnds, "eef::TableComposition::addbutton"); //$NON-NLS-1$
    Button removeEnds = new Button(endsPanel, SWT.NONE);
    removeEnds.setText(DeploymentMessages.PropertiesEditionPart_RemoveTableViewerLabel);
    removeEnds.setEnabled(false);
    removeEnds.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData removeEndsData = new GridData(GridData.FILL_HORIZONTAL);
    removeEnds.setLayoutData(removeEndsData);
    removeEnds.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        if (ends.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) ends.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            EObject selectedElement = (EObject) selection.getFirstElement();
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.REMOVE, null, selectedElement));
            ends.refresh();
          }
        }
      }

    });
    EditingUtils.setID(removeEnds, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends);
    EditingUtils.setEEFtype(removeEnds, "eef::TableComposition::removebutton"); //$NON-NLS-1$
    Button editEnds = new Button(endsPanel, SWT.NONE);
    editEnds.setText(DeploymentMessages.PropertiesEditionPart_EditTableViewerLabel);
    editEnds.setEnabled(false);
    editEnds.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData editEndsData = new GridData(GridData.FILL_HORIZONTAL);
    editEnds.setLayoutData(editEndsData);
    editEnds.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        if (ends.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) ends.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
            ends.refresh();
          }
        }
      }

    });
    EditingUtils.setID(editEnds, DeploymentViewsRepository.ConnectionEnds.InternalEndPoint.ends);
    EditingUtils.setEEFtype(editEnds, "eef::TableComposition::editbutton"); //$NON-NLS-1$
    return endsPanel;
  }



	/**
   * @generated
   */
  protected Composite createExternalEndPointGroup(Composite parent) {
    Group externalEndPointGroup = new Group(parent, SWT.NONE);
    externalEndPointGroup.setText(DeploymentMessages.ConnectionEndsPropertiesEditionPart_ExternalEndPointGroupLabel);
    GridData externalEndPointGroupData = new GridData(GridData.FILL_HORIZONTAL);
    externalEndPointGroupData.horizontalSpan = 3;
    externalEndPointGroup.setLayoutData(externalEndPointGroupData);
    GridLayout externalEndPointGroupLayout = new GridLayout();
    externalEndPointGroupLayout.numColumns = 3;
    externalEndPointGroup.setLayout(externalEndPointGroupLayout);
    return externalEndPointGroup;
  }

  /**
   * @param container
   * @generated
   */
  protected Composite createExternalEndPointTableComposition(Composite container) {
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridLayout tableContainerLayout = new GridLayout();
    GridData tableContainerData = new GridData(GridData.FILL_BOTH);
    tableContainerData.horizontalSpan = 3;
    tableContainer.setLayoutData(tableContainerData);
    tableContainerLayout.numColumns = 2;
    tableContainer.setLayout(tableContainerLayout);
    org.eclipse.swt.widgets.Table tableExternalEndPoint = new org.eclipse.swt.widgets.Table(tableContainer, SWT.FULL_SELECTION);
    tableExternalEndPoint.setHeaderVisible(true);
    tableExternalEndPoint.setEnabled(false);
    tableExternalEndPoint.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData gdExternalEndPoint = new GridData();
    gdExternalEndPoint.grabExcessHorizontalSpace = true;
    gdExternalEndPoint.horizontalAlignment = GridData.FILL;
    gdExternalEndPoint.grabExcessVerticalSpace = true;
    gdExternalEndPoint.verticalAlignment = GridData.FILL;
    tableExternalEndPoint.setLayoutData(gdExternalEndPoint);
    tableExternalEndPoint.setLinesVisible(true);

        TableColumn name = new TableColumn(tableExternalEndPoint, SWT.NONE);
        name.setWidth(80);
        name.setText("Label"); //$NON-NLS-1$

    externalEndPoint = new TableViewer(tableExternalEndPoint);
    externalEndPoint.setContentProvider(new ArrayContentProvider());
    externalEndPoint.setLabelProvider(new ITableLabelProvider() {
            public String getColumnText(Object object, int columnIndex) {
              AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
              if (object instanceof EObject) {
                switch (columnIndex) {
                case 0:
                  return labelProvider.getText(object);
                }
              }
              return ""; //$NON-NLS-1$
            }
      
            public Image getColumnImage(Object element, int columnIndex) {
              return null;
            }
      

      public void addListener(ILabelProviderListener listener) {
      }

      public void dispose() {
      }

      public boolean isLabelProperty(Object element, String property) {
        return false;
      }

      public void removeListener(ILabelProviderListener listener) {
      }

    });
    externalEndPoint.getTable().addListener(SWT.MouseDoubleClick, new Listener(){

      public void handleEvent(Event event) {
        if (externalEndPoint.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) externalEndPoint.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
            externalEndPoint.refresh();
          }
        }
      }

    });
    GridData externalEndPointData = new GridData(GridData.FILL_HORIZONTAL);
    externalEndPointData.minimumHeight = 120;
    externalEndPointData.heightHint = 120;
    externalEndPoint.getTable().setLayoutData(externalEndPointData);
    for (ViewerFilter filter : this.externalEndPointFilters) {
      externalEndPoint.addFilter(filter);
    }
    EditingUtils.setID(externalEndPoint.getTable(), DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_);
    EditingUtils.setEEFtype(externalEndPoint.getTable(), "eef::TableComposition::field"); //$NON-NLS-1$
    createExternalEndPointPanel(tableContainer);
    return container;
  }

  /**
   * @param container
   * @generated
   */
  protected Composite createExternalEndPointPanel(Composite container) {
    Composite externalEndPointPanel = new Composite(container, SWT.NONE);
    GridLayout externalEndPointPanelLayout = new GridLayout();
    externalEndPointPanelLayout.numColumns = 1;
    externalEndPointPanel.setLayout(externalEndPointPanelLayout);
    Button addExternalEndPoint = new Button(externalEndPointPanel, SWT.NONE);
    addExternalEndPoint.setText(DeploymentMessages.PropertiesEditionPart_AddTableViewerLabel);
    addExternalEndPoint.setEnabled(false);
    addExternalEndPoint.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData addExternalEndPointData = new GridData(GridData.FILL_HORIZONTAL);
    addExternalEndPoint.setLayoutData(addExternalEndPointData);
    addExternalEndPoint.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, null));
        externalEndPoint.refresh();
      }
    });
    EditingUtils.setID(addExternalEndPoint, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_);
    EditingUtils.setEEFtype(addExternalEndPoint, "eef::TableComposition::addbutton"); //$NON-NLS-1$
    Button removeExternalEndPoint = new Button(externalEndPointPanel, SWT.NONE);
    removeExternalEndPoint.setText(DeploymentMessages.PropertiesEditionPart_RemoveTableViewerLabel);
    removeExternalEndPoint.setEnabled(false);
    removeExternalEndPoint.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData removeExternalEndPointData = new GridData(GridData.FILL_HORIZONTAL);
    removeExternalEndPoint.setLayoutData(removeExternalEndPointData);
    removeExternalEndPoint.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        if (externalEndPoint.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) externalEndPoint.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            EObject selectedElement = (EObject) selection.getFirstElement();
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.REMOVE, null, selectedElement));
            externalEndPoint.refresh();
          }
        }
      }

    });
    EditingUtils.setID(removeExternalEndPoint, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_);
    EditingUtils.setEEFtype(removeExternalEndPoint, "eef::TableComposition::removebutton"); //$NON-NLS-1$
    Button editExternalEndPoint = new Button(externalEndPointPanel, SWT.NONE);
    editExternalEndPoint.setText(DeploymentMessages.PropertiesEditionPart_EditTableViewerLabel);
    editExternalEndPoint.setEnabled(false);
    editExternalEndPoint.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData editExternalEndPointData = new GridData(GridData.FILL_HORIZONTAL);
    editExternalEndPoint.setLayoutData(editExternalEndPointData);
    editExternalEndPoint.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        if (externalEndPoint.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) externalEndPoint.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
            externalEndPoint.refresh();
          }
        }
      }

    });
    EditingUtils.setID(editExternalEndPoint, DeploymentViewsRepository.ConnectionEnds.ExternalEndPoint.externalEndPoint_);
    EditingUtils.setEEFtype(editExternalEndPoint, "eef::TableComposition::editbutton"); //$NON-NLS-1$
    return externalEndPointPanel;
  }

  /**
   * @generated
   */
  protected Composite createExternalReferenceGroup(Composite parent) {
    Group externalReferenceGroup = new Group(parent, SWT.NONE);
    externalReferenceGroup.setText(DeploymentMessages.ConnectionEndsPropertiesEditionPart_ExternalReferenceGroupLabel);
    GridData externalReferenceGroupData = new GridData(GridData.FILL_HORIZONTAL);
    externalReferenceGroupData.horizontalSpan = 3;
    externalReferenceGroup.setLayoutData(externalReferenceGroupData);
    GridLayout externalReferenceGroupLayout = new GridLayout();
    externalReferenceGroupLayout.numColumns = 3;
    externalReferenceGroup.setLayout(externalReferenceGroupLayout);
    return externalReferenceGroup;
  }

  /**
   * @param container
   * @generated
   */
  protected Composite createExternalReferenceTableComposition(Composite container) {
    Composite tableContainer = new Composite(container, SWT.NONE);
    GridLayout tableContainerLayout = new GridLayout();
    GridData tableContainerData = new GridData(GridData.FILL_BOTH);
    tableContainerData.horizontalSpan = 3;
    tableContainer.setLayoutData(tableContainerData);
    tableContainerLayout.numColumns = 2;
    tableContainer.setLayout(tableContainerLayout);
    org.eclipse.swt.widgets.Table tableExternalReference = new org.eclipse.swt.widgets.Table(tableContainer, SWT.FULL_SELECTION);
    tableExternalReference.setHeaderVisible(true);
    tableExternalReference.setEnabled(false);
    tableExternalReference.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData gdExternalReference = new GridData();
    gdExternalReference.grabExcessHorizontalSpace = true;
    gdExternalReference.horizontalAlignment = GridData.FILL;
    gdExternalReference.grabExcessVerticalSpace = true;
    gdExternalReference.verticalAlignment = GridData.FILL;
    tableExternalReference.setLayoutData(gdExternalReference);
    tableExternalReference.setLinesVisible(true);

        TableColumn name = new TableColumn(tableExternalReference, SWT.NONE);
        name.setWidth(80);
        name.setText("Label"); //$NON-NLS-1$

    externalReference = new TableViewer(tableExternalReference);
    externalReference.setContentProvider(new ArrayContentProvider());
    externalReference.setLabelProvider(new ITableLabelProvider() {
            public String getColumnText(Object object, int columnIndex) {
              AdapterFactoryLabelProvider labelProvider = new AdapterFactoryLabelProvider(adapterFactory);
              if (object instanceof EObject) {
                switch (columnIndex) {
                case 0:
                  return labelProvider.getText(object);
                }
              }
              return ""; //$NON-NLS-1$
            }
      
            public Image getColumnImage(Object element, int columnIndex) {
              return null;
            }
      

      public void addListener(ILabelProviderListener listener) {
      }

      public void dispose() {
      }

      public boolean isLabelProperty(Object element, String property) {
        return false;
      }

      public void removeListener(ILabelProviderListener listener) {
      }

    });
    externalReference.getTable().addListener(SWT.MouseDoubleClick, new Listener(){

      public void handleEvent(Event event) {
        if (externalReference.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) externalReference.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
            externalReference.refresh();
          }
        }
      }

    });
    GridData externalReferenceData = new GridData(GridData.FILL_HORIZONTAL);
    externalReferenceData.minimumHeight = 120;
    externalReferenceData.heightHint = 120;
    externalReference.getTable().setLayoutData(externalReferenceData);
    for (ViewerFilter filter : this.externalReferenceFilters) {
      externalReference.addFilter(filter);
    }
    EditingUtils.setID(externalReference.getTable(), DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_);
    EditingUtils.setEEFtype(externalReference.getTable(), "eef::TableComposition::field"); //$NON-NLS-1$
    createExternalReferencePanel(tableContainer);
    return container;
  }

  /**
   * @param container
   * @generated
   */
  protected Composite createExternalReferencePanel(Composite container) {
    Composite externalReferencePanel = new Composite(container, SWT.NONE);
    GridLayout externalReferencePanelLayout = new GridLayout();
    externalReferencePanelLayout.numColumns = 1;
    externalReferencePanel.setLayout(externalReferencePanelLayout);
    Button addExternalReference = new Button(externalReferencePanel, SWT.NONE);
    addExternalReference.setText(DeploymentMessages.PropertiesEditionPart_AddTableViewerLabel);
    addExternalReference.setEnabled(false);
    addExternalReference.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData addExternalReferenceData = new GridData(GridData.FILL_HORIZONTAL);
    addExternalReference.setLayoutData(addExternalReferenceData);
    addExternalReference.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.ADD, null, null));
        externalReference.refresh();
      }
    });
    EditingUtils.setID(addExternalReference, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_);
    EditingUtils.setEEFtype(addExternalReference, "eef::TableComposition::addbutton"); //$NON-NLS-1$
    Button removeExternalReference = new Button(externalReferencePanel, SWT.NONE);
    removeExternalReference.setText(DeploymentMessages.PropertiesEditionPart_RemoveTableViewerLabel);
    removeExternalReference.setEnabled(false);
    removeExternalReference.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData removeExternalReferenceData = new GridData(GridData.FILL_HORIZONTAL);
    removeExternalReference.setLayoutData(removeExternalReferenceData);
    removeExternalReference.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        if (externalReference.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) externalReference.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            EObject selectedElement = (EObject) selection.getFirstElement();
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_, PropertiesEditionEvent.CHANGE, PropertiesEditionEvent.REMOVE, null, selectedElement));
            externalReference.refresh();
          }
        }
      }

    });
    EditingUtils.setID(removeExternalReference, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_);
    EditingUtils.setEEFtype(removeExternalReference, "eef::TableComposition::removebutton"); //$NON-NLS-1$
    Button editExternalReference = new Button(externalReferencePanel, SWT.NONE);
    editExternalReference.setText(DeploymentMessages.PropertiesEditionPart_EditTableViewerLabel);
    editExternalReference.setEnabled(false);
    editExternalReference.setToolTipText(DeploymentMessages.ConnectionEnds_ReadOnly);
    GridData editExternalReferenceData = new GridData(GridData.FILL_HORIZONTAL);
    editExternalReference.setLayoutData(editExternalReferenceData);
    editExternalReference.addSelectionListener(new SelectionAdapter() {

      /**
       * {@inheritDoc}
       * 
       * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
       * @generated
       */
      public void widgetSelected(SelectionEvent e) {
        if (externalReference.getSelection() instanceof IStructuredSelection) {
          IStructuredSelection selection = (IStructuredSelection) externalReference.getSelection();
          if (selection.getFirstElement() instanceof EObject) {
            propertiesEditionComponent.firePropertiesChanged(new PropertiesEditionEvent(ConnectionEndsPropertiesEditionPartImpl.this, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_, PropertiesEditionEvent.COMMIT, PropertiesEditionEvent.EDIT, null, selection.getFirstElement()));
            externalReference.refresh();
          }
        }
      }

    });
    EditingUtils.setID(editExternalReference, DeploymentViewsRepository.ConnectionEnds.ExternalReference.externalReference_);
    EditingUtils.setEEFtype(editExternalReference, "eef::TableComposition::editbutton"); //$NON-NLS-1$
    return externalReferencePanel;
  }

  /**
	 * {@inheritDoc}
	 * 
	 * @see org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionListener#firePropertiesChanged(org.eclipse.emf.eef.runtime.api.notify.IPropertiesEditionEvent)
	 * @generated
	 */
	public void firePropertiesChanged(IPropertiesEditionEvent event) {
  }



	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#initEnds(EObject current, EReference containingFeature, EReference feature)
	 */
	public void initEnds(ReferencesTableSettings settings) {
		if (current.eResource() != null && current.eResource().getResourceSet() != null)
			this.resourceSet = current.eResource().getResourceSet();
		ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
		ends.setContentProvider(contentProvider);
		ends.setInput(settings);
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#updateEnds()
	 * @generated
	 */
	public void updateEnds() {
  ends.refresh();
}

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#addFilterEnds(ViewerFilter filter)
	 * @generated
	 */
	public void addFilterToEnds(ViewerFilter filter) {
    endsFilters.add(filter);
    if (this.ends != null) {
      this.ends.addFilter(filter);
    }
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#addBusinessFilterEnds(ViewerFilter filter)
	 * @generated
	 */
	public void addBusinessFilterToEnds(ViewerFilter filter) {
    endsBusinessFilters.add(filter);
  }

	/**
	 * {@inheritDoc}
	 * 
	 * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#isContainedInEndsTable(EObject element)
	 * @generated
	 */
	public boolean isContainedInEndsTable(EObject element) {
    return ((ReferencesTableSettings)ends.getInput()).contains(element);
  }







	/**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#initExternalEndPoint(EObject current, EReference containingFeature, EReference feature)
   */
  public void initExternalEndPoint(ReferencesTableSettings settings) {
    if (current.eResource() != null && current.eResource().getResourceSet() != null)
      this.resourceSet = current.eResource().getResourceSet();
    ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
    externalEndPoint.setContentProvider(contentProvider);
    externalEndPoint.setInput(settings);
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#updateExternalEndPoint()
   * @generated
   */
  public void updateExternalEndPoint() {
  externalEndPoint.refresh();
}

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#addFilterExternalEndPoint(ViewerFilter filter)
   * @generated
   */
  public void addFilterToExternalEndPoint(ViewerFilter filter) {
    externalEndPointFilters.add(filter);
    if (this.externalEndPoint != null) {
      this.externalEndPoint.addFilter(filter);
    }
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#addBusinessFilterExternalEndPoint(ViewerFilter filter)
   * @generated
   */
  public void addBusinessFilterToExternalEndPoint(ViewerFilter filter) {
    externalEndPointBusinessFilters.add(filter);
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#isContainedInExternalEndPointTable(EObject element)
   * @generated
   */
  public boolean isContainedInExternalEndPointTable(EObject element) {
    return ((ReferencesTableSettings)externalEndPoint.getInput()).contains(element);
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#initExternalReference(EObject current, EReference containingFeature, EReference feature)
   */
  public void initExternalReference(ReferencesTableSettings settings) {
    if (current.eResource() != null && current.eResource().getResourceSet() != null)
      this.resourceSet = current.eResource().getResourceSet();
    ReferencesTableContentProvider contentProvider = new ReferencesTableContentProvider();
    externalReference.setContentProvider(contentProvider);
    externalReference.setInput(settings);
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#updateExternalReference()
   * @generated
   */
  public void updateExternalReference() {
  externalReference.refresh();
}

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#addFilterExternalReference(ViewerFilter filter)
   * @generated
   */
  public void addFilterToExternalReference(ViewerFilter filter) {
    externalReferenceFilters.add(filter);
    if (this.externalReference != null) {
      this.externalReference.addFilter(filter);
    }
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#addBusinessFilterExternalReference(ViewerFilter filter)
   * @generated
   */
  public void addBusinessFilterToExternalReference(ViewerFilter filter) {
    externalReferenceBusinessFilters.add(filter);
  }

  /**
   * {@inheritDoc}
   * 
   * @see org.omg.deployment.parts.ConnectionEndsPropertiesEditionPart#isContainedInExternalReferenceTable(EObject element)
   * @generated
   */
  public boolean isContainedInExternalReferenceTable(EObject element) {
    return ((ReferencesTableSettings)externalReference.getInput()).contains(element);
  }

  /**
	 * {@inheritDoc}
	 *
	 * @see org.eclipse.emf.eef.runtime.api.parts.IPropertiesEditionPart#getTitle()
	 * @generated
	 */
	public String getTitle() {
    return DeploymentMessages.ConnectionEnds_Part_Title;
  }



}
